package com.ele.Servlet;

import com.ele.Pojo.PageResult;
import com.ele.Pojo.vo.FoodCategoryVO;
import com.ele.Service.FoodCategoryService;
import com.ele.Service.impl.FoodCategoryServiceImpl;
import com.google.gson.Gson;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

/**
 * 分页查询
 */
@WebServlet("/findFoodCategory")
public class FindFoodCategoryServlet extends HttpServlet {
    //Service
    private FoodCategoryService foodCategoryService = new FoodCategoryServiceImpl();

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String currentPage = req.getParameter("currentPage");
        String pageSize = req.getParameter("pageSize");
        String shopId = req.getParameter("shopId");

        //返回一个集合
        PageResult<List<FoodCategoryVO>> list = this.foodCategoryService.findFoodCategory(currentPage,pageSize,shopId);

        String json =new Gson().toJson(list);

        resp.setContentType("application/json;charset=utf-8");
        resp.getWriter().write(json);

    }
}
